package animation;

import graphics.MaxGraphics;

import java.awt.Color;
import java.awt.Polygon;
import java.awt.Shape;

import ship.ShipConstants;
import structure.SObject;
import util.Point;

public class ExplodingShip extends SObject {
	private Point[] pos = new Point[ShipConstants.model.length];
	private Point[] vel = new Point[ShipConstants.model.length];
	private double[] angle = new double[ShipConstants.model.length];
	private double[] angleVel = new double[ShipConstants.model.length];
	
	public ExplodingShip(Point p, double originalAngle) {
		super(p);
		int i = 0;
		for(Polygon poly : ShipConstants.model) {
			pos[i++] = new Point(0, 0);
		}
		for(i = 0; i < angle.length; i++) {
			angle[i] = originalAngle;
		}
		for(i = 0; i < angleVel.length; i++) {
			angleVel[i] = (Math.random() / 20) - .05;
		}
		for(i = 0; i < vel.length; i++) {
			vel[i] = new Point((Math.random() / 20) - .05, (Math.random() / 20) - .05);
		}
	}

	@Override
	public void draw(MaxGraphics g) {
		g.translate(getX(), getY());


		g.setColor(Color.BLUE);
		int i = 0;
		for(Polygon p : ShipConstants.model) {
			g.translate(pos[i].getX(), pos[i].getY());
			
			g.rotate(angle[i]);
			g.fillPolygon(p);
			

			
			g.rotate(-angle[i]);
			
			g.translate(-pos[i].getX(), -pos[i].getY());
			angle[i] += angleVel[i];
			pos[i] = new Point(pos[i].getX() + vel[i].getX(), pos[i].getY() + vel[i].getY());
			i++;
			
		}
		
		g.translate(-getX(), -getY());
	}

	@Override
	public void collide(SObject s) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Shape[] getShape() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public double getRadius() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return null;
	}

}
